package com.cssw.fyzb.core.dao.live;

import com.cssw.fyzb.core.model.dodb.CmfLivePk;
import org.springframework.stereotype.Repository;

import java.util.Date;

/**
 * @Author: wondream
 * @Date: 2020/12/24 20:36
 */
@Repository
public class LivePkDaoImpl implements LivePkDao {

    @Override
    public CmfLivePk findById(Long pkId) {
        return CmfLivePk.dao.findById(pkId);
    }

    @Override
    public Long addLivePk(Long fromAnchorId, Long fromLiveId, Long toAnchorId, Long toLiveId, Date beginTime) {
        CmfLivePk cmfLivePk = new CmfLivePk();
        cmfLivePk.setFromAnchorId(fromAnchorId);
        cmfLivePk.setFromLiveId(fromLiveId);
        cmfLivePk.setToAnchorId(toAnchorId);
        cmfLivePk.setToLiveId(toLiveId);
        cmfLivePk.setBeginTime(beginTime);
        cmfLivePk.setStatus(CmfLivePk.STATUS_PKING);
        cmfLivePk.save();
        return cmfLivePk.getPiId();
    }

    @Override
    public void closeLivePk(Long id) {
        CmfLivePk cmfLivePk = CmfLivePk.dao.findById(id);
        cmfLivePk.setStatus(CmfLivePk.STATUS_COMPLETE);
        cmfLivePk.setEndTime(new Date());
        cmfLivePk.update();
    }


}
